#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct stock
{
	int* a;
	int top;
	int capacity;
}ST;
void StockInit(ST* st)
{
	st->a = NULL;
	st->capacity = 0;
	st->top = -1;
}

void StockPush(ST* st, int x)
{
	if (st->top + 1 == st->capacity)
	{
		//扩容
		int newcapaciy = st->capacity == 0 ? 3 : st->capacity * 2;
		int* p = (int*)malloc(sizeof(int) * newcapaciy);
		//当空间不够存在a的地址被改变的问题
		//所以用循环把以前的数组元素转移
		for (int i = 0; i < st->capacity; i++)
		{
			p[i] = st->a[i];
		}
		st->a = p;
		st->capacity = newcapaciy;
	}
	st->top++;
	st->a[st->top] = x;
}

bool  StockEmpty(ST* st)
{
	return st->top == -1;
}

int StockTop(ST* st)
{
	return st->a[st->top];
}

void StockPop(ST* st)
{
	st->top--;
}
int main()
{

	//若想把十进制转化为其他进制 只需要改变N即可；
	//但是十六进制有点特殊 有abdcdf 所以不能直接这样做
	int n = 0;
	ST st;
	StockInit(&st);
	printf("====进制转换器====\n");
	printf("请输入要转换的数\n");
	scanf("%d", &n);
	printf("要转换的进制是？\n");
	int N = 0;
	scanf("%d", &N);
	while (n)
	{
		/*printf("%d ", n % 2);
		n = n / 2;*/
		//入栈
		/*switch (n % N)
		{
		case 0:
			StockPush(&st, '0');
			break;
		case 1:
			StockPush(&st, '1');
			break;
		case 2:
			StockPush(&st, '2');
			break;
		case 3:
			StockPush(&st, '3');
			break;
		case 4:
			StockPush(&st, '4');
			break;
		case 5:
			StockPush(&st, '5');
			break;
		case 6:
			StockPush(&st, '6');
			break;
		case 7:
			StockPush(&st, '7');
			break;
		case 8:
			StockPush(&st, '8');
			break;
		case 9:
			StockPush(&st, '9');
			break;
		case 10:
			StockPush(&st, 'a');
			break;
		case 11:
			StockPush(&st, 'b');
			break;
		case 12:
			StockPush(&st, 'c');
			break;
		case 13:
			StockPush(&st, 'd');
			break;
		case 14:
			StockPush(&st, 'e');
			break;
		case 15:
			StockPush(&st, 'f');
			break;
	}*/
		StockPush(&st, n%N);
		n = n / N;
	}
	printf("结果是:");
	while (!StockEmpty(&st))
	{
		if (StockTop(&st) < 10)
		{
			printf("%d", StockTop(&st));
		}
		else
		{
			printf("%c", StockTop(&st)+55);
		}
		StockPop(&st);
	}
	return 0;
}